home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / NextDeveloper / Examples / AppKit / ScrollDoodScroll / PostScriptView.m < prev    next >
Text File  |  1992-05-28  |  2KB  |  84 lines

  1. // PostScriptView.m
  2. // By Jayson Adams, NeXT Developer Support Team
  3. // You may freely copy, distribute and reuse the code in this example.
  4. // NeXT disclaims any warranty of any kind, expressed or implied, as to its
  5. // fitness for any particular use.
  6.  
  7. #import <dpsclient/psops.h>
  8. #import <appkit/NXImage.h>
  9.  
  10. #import "PostScriptView.h"
  11.  
  12. @implementation PostScriptView
  13.  
  14.  
  15. /* instance methods */
  16.  
  17. - initFrame:(const NXRect *)frameRect
  18. {
  19.     [super initFrame:frameRect];
  20.  
  21.   /*
  22.    * create an nximage to hold the PostScript image contained in our MachO
  23.    * segment, created by Makefile.preamble; we'll "draw" by compositing the
  24.    * resulting bits into ourself.  By making the image scalable, we can scale
  25.    * the bitmap image by changing our nximage's size
  26.    */
  27.  
  28.     postscriptImage = [[[NXImage alloc] initFromSection:"SampleImage"]
  29.                                      setScalable:YES];
  30.     
  31.     return self;
  32. }
  33.     
  34. - free
  35. {
  36.     [postscriptImage free];
  37.     
  38.     return [super free];
  39. }
  40.  
  41. - scale:(float)factor
  42. {
  43.     NXSize    aSize;
  44.  
  45.   /*
  46.    * if we resize the nximage, it will reexcute the PostScript
  47.    * image with the new scale factor (resulting in a bitmap image that's
  48.    * larger or smaller than before)
  49.    */
  50.     [postscriptImage getSize:&aSize];
  51.     aSize.width *= factor;
  52.     aSize.height *= factor;
  53.     [postscriptImage setSize:&aSize];
  54.  
  55.     aSize.width = NX_WIDTH(&bounds) * factor;
  56.     aSize.height = NX_HEIGHT(&bounds) * factor;
  57.     [self sizeTo:aSize.width :aSize.height];
  58.    
  59.   /* show the new image */
  60.     [self display];
  61.     
  62.     return self;
  63. }
  64.  
  65. - drawSelf:(const NXRect *)rects :(int)rectCount
  66. {
  67.   /* erase update rect since the nximage might be smaller than our bounds */
  68.     PSsetgray(NX_WHITE);
  69.     NXRectFill(&(rects[0]));
  70.     
  71.   /*
  72.    * copy the bits from the nximage into ourself;  note that we need not check
  73.    * to see if we're printing since the nximage will do the right thing (i.e.
  74.    * spit out PostScript) if we are
  75.    */
  76.     
  77.     [postscriptImage composite:NX_SOVER
  78.                  fromRect:&(rects[0])
  79.              toPoint:&(rects[0].origin)];
  80.     
  81.     return self;
  82. }
  83.  
  84. @end